package com.ftm.service.impl;

import java.util.List;

import com.ftm.dao.ShopCarDao;
import com.ftm.dao.impl.ShopCarDaoImpl;
import com.ftm.entity.Shop;
import com.ftm.entity.Shopc;
import com.ftm.service.ShopCarService;
import com.ftm.tools.DBTools;
import com.ftm.tools.PageData;

/**
 * 购物车业务类
 * 
 * @author zcl
 *
 */
public class ShopCarServiceImpl implements ShopCarService {
	ShopCarDao sc = new ShopCarDaoImpl();

	@Override
	public PageData<Shopc> showShopCar(int userid, int page, int pageSize, String keywords) {
		if (page < 1) {
			page = 1;
		} else if (page > pageSize) {
			page = pageSize;
		}
		PageData<Shopc> pd = sc.selShopCar(userid, page, pageSize, keywords);
		if (pd == null)
			return null;
		return pd;
	}

	@Override
	public boolean delGoods(int userid, String goodsname) {
		boolean flag = sc.delShopCar(userid, goodsname);
		if (flag)
			return true;
		return false;
	}

	@Override
	public boolean addGoods(Shopc shopc) {
		boolean flag = sc.addShopCar(shopc);
		if (flag)
			return true;
		return false;
	}

	@Override
	public Shopc showShopName(Shopc shopc) {
		String sql = "select shopname from ftm_shop where shopid=?";
		List<Shop> list = (List<Shop>) DBTools.exQuery(sql, Shop.class, shopc.getShopid());
		if (list.size() == 0) {
			return null;
		}
		Shopc shopc1 = new Shopc(shopc.getUserid(), shopc.getShopid(), shopc.getGoodsname(), shopc.getShopccount(),
				shopc.getTotal(), list.get(0).getShopname());
		System.out.println(shopc1.getShopname());
		return shopc1;
	}
}
